package queue;

import java.util.PriorityQueue;

//1046. 最后一块石头的重量
public class Num1046_lastStoneWeight {
    public int lastStoneWeight(int[] stones) {
        PriorityQueue<Integer>queue = new PriorityQueue<>((a , b) -> b -a);
        for (int num : stones){
            queue.offer(num);
        }
        while (queue.size() > 1){
            int n = Math.abs(queue.poll() - queue.poll());
            if (n != 0){
                queue.offer(n);
            }
        }
        return queue.isEmpty() ? 0 : queue.peek();
    }
}
